from django.http import JsonResponse
from stw_app import models


# 装饰器名字
def already_login(func):
    def alr_login(request, *args, **kwargs):
        session_instance = models.Session.objects.first().userid
        print(session_instance)
        # 判断是否已经登录了
        if session_instance:
            return func(request, *args, **kwargs)
        else:
            # 没登录的先登录
            return JsonResponse({'success': False, 'title': '未登录', 'message': '您暂未登录，请登录后再试'})

    return alr_login
